<?php

namespace App\Model;


class GameFreeOrderTask extends Model
{

    protected $table = 'game_free_order_task';

    public static function getValidFreeOrderTask($uid, $gameId)
    {
//`id` int unsigned NOT NULL AUTO_INCREMENT,
//`uid` int NOT NULL DEFAULT '0' COMMENT '用户ID',
//`game_id` int NOT NULL DEFAULT '0' COMMENT '游戏ID',
//`product_id` int NOT NULL DEFAULT '0' COMMENT '商品ID',
//`product_sku_id` int NOT NULL DEFAULT '0' COMMENT '商品skuID',
//`level` tinyint(1) NOT NULL DEFAULT '1' COMMENT '完成阶段1=备货2=打包3=出库',
//`prize_id` int NOT NULL DEFAULT '0' COMMENT '完成道具ID',
//`prize_lv1` int NOT NULL DEFAULT '0' COMMENT '第一阶段获得道具数量',
//`prize_lv2` int NOT NULL DEFAULT '0' COMMENT '第二阶段获得道具数量',
//`prize_lv3` int NOT NULL DEFAULT '0' COMMENT '第三阶段获得道具数量',
//`create_at` int NOT NULL COMMENT '开始日期',
//`end_at` int NOT NULL COMMENT '失效日期',
//`status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '任务状态1=有效2=失效',
        try {
            $where = [
                ['uid', '=', $uid],
                ['game_id', '=', $gameId],
                ['status', '=', 1],
                ['end_at', '>', time()]
            ];
            $data = self::query()->where($where)->first();
            if (empty($data)) {
                return ['code' => 2, 'msg' => '未找到记录1！'];
            }
            return ['code' => 0, 'msg' => '获取成功！', 'data' => $data->toArray()];
        } catch (\Exception $e) {
            return ['code' => 1, 'msg' => $e->getMessage()];
        }
    }
}